package org.oa.dao.impl;

import java.io.Serializable;

import javax.annotation.Resource;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.oa.dao.UserDao;
import org.oa.dto.User;

import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
/**
 * Spring 给我们提供的HibernateDaoSupport，可以非常方便的实现数据库的操作
 * @author Administrator
 *
 */
@Repository
public class UserDaoImpl extends HibernateDaoSupport implements UserDao{
	
	/**
	 * 注入需要的SessionFactory
	 * @param sessionFactory
	 */
	@Resource
	public void MySessionFactory(SessionFactory sessionFactory){
		super.setSessionFactory(sessionFactory);
	}
	
	public Long save(User user) {
		System.out.println("-----保存成功----");
		//通过currentSession()方法获取Session对象
		Session session = currentSession();
		Serializable ids = session.save(user);
		Long id = (Long)ids;
		return id;
	}
}
